package com.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.springcloud.alibaba.config.BlockHandler;
import com.springcloud.configclient.commons.entities.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RateLimitControler {


    @GetMapping(value = "/byresource")
    @SentinelResource(value = "byresource",blockHandler = "dealHotKey")
    public CommonResult hotKey() {
        return new CommonResult(222,"成功");
    }
    public CommonResult dealHotKey(BlockException e) {
        return new CommonResult(444,e.getMessage());
    }

    @GetMapping(value = "/byresource1")
    @SentinelResource(value = "byresource1",blockHandler = "blockException1",blockHandlerClass = BlockHandler.class)
    public CommonResult hotKey1() {
        return new CommonResult(222,"成功");
    }

}
